package com.xlhj.boot.util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author: caijliu
 * @description: 日期时间工具类
 * @data: 23/06/2021 16:13
 */
public class DateUtils {

    /**
     * 返回指定格式的当前日期
     * @return
     */
    public static String getLocalDateStr() {
        LocalDate localDate = LocalDate.now();
        String format = localDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        return format;
    }

    /**
     * 根据Date格式化日期时间
     * @param date
     * @return
     */
    public static String getDateToStr(Date date) {
        Instant instant = date.toInstant();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return format;
    }
}
